package org.bookie.hibernate;

import org.apache.hivemind.service.ThreadCleanupListener;
import org.hibernate.Session;

/**
 * Adapter adapts {@link Session} interface to the {@link ThreadCleanupListener} 
 * for closing session when thread ends
 * 
 * @author zubairov
 */
public class SessionCloserAdapter implements ThreadCleanupListener {

	private Session session;

	/**
	 * Constructor
	 * @param session wrapped session
	 */
	public SessionCloserAdapter(Session session) {
		this.session = session;
	}

	public void threadDidCleanup() {
		session.flush();
		session.close();
	}

}
